package com.eshop.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class WarningOperateDao {

	private Connection conn = null;
	private PreparedStatement sta = null;
	private ResultSet r = null;
	
	public int warningShlves(String status, String goodsId)
	{
		int i = 0;
		String sql = "";
		try {
			conn = Conn.getConn();
			
			if("1".equals(status))
			{
				sql = "update goods set goods_status = 0 where goods_id = ?";
			}
			if("0".equals(status))
			{
				sql = "update goods set goods_status = 1 where goods_id = ?";
			}
			
			sta = conn.prepareStatement(sql);
			sta.setObject(1, goodsId);
			i = sta.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				if(r != null)
				{
					r.close();
				}
				if(sta != null)
				{
					sta.close();
				}
				if(conn != null)
				{
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}	
		return i;
	}
	
	public int warningDelete(String goodsId)
	{
		int i =0;
		try {
			conn = Conn.getConn();
			String sql = "update goods set goods_exist = 0 where goods_id = ?";
			sta = conn.prepareStatement(sql);
			sta.setObject(1, goodsId);
			i = sta.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				if(r != null)
				{
					r.close();
				}
				if(sta != null)
				{
					sta.close();
				}
				if(conn != null)
				{
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}		
		return i;
	}
}
